// EG4Data.h -- data structure for holding sim data
// Created: Nov. 12, 2023 by Asia SUN, asia.rabbit@163.com
// Last modified: Sept. 24, 2024, by Asia SUN

#ifndef EG4Data_h
#define EG4Data_h

#include <vector>
#include <Rtypes.h>
#include "G4ThreeVector.hh"
#include "TObject.h"

using std::vector;

struct hit_t{
  int pid, tid; // parent id, track id
  int id[2];
  double a, z;
  double t, v, ek, de; // de: energy deposit
  double p[3], pos[3]; // momentum and position
  double trkLen; // total track length from target to TOFW

  void initialize(){
    pid = tid = id[0] = id[1] = -1;
    a = z = t = v = ek = de = trkLen = -999.;
    for(int i = 3; i--;) p[i] = pos[i] = -999.;
  } // end member function initialize
};

// data for each event
class EG4Data{
public:
  EG4Data();
  virtual ~EG4Data(){}

  void Initialize();
  void PostAssign();
  static void copy(double *pp, const G4ThreeVector &p);
  double pphi() const;

  int index; // event index
  int nhT1, nhTOFW, nhDCTaD, nhDC, nhNWS, nhNWF, nhNWV; // multiplicity
  double a, z; // particle identity
  double p0[3], pos[3]; // initial momentum (in MeV/c) and position (in mm)
  double pp0, theta, phi; // incident momentum (in MeV/c) and angle (phi and theta in deg)
  double tof; // TOF

  hit_t hT1;
  hit_t hNWV;
  vector<hit_t> hTOFW;
  vector<hit_t> hDCTaD; // 2*4 = [DC0-1][x0-1--y0-1]
  vector<hit_t> hDC; // 3*6 = [DC0-1-2][x0-1--u0-1--v0-1]
  vector<hit_t> hNWS;
  vector<hit_t> hNWF;

  ClassDef(EG4Data, 1) // EG4 simulation data class
};

#endif
